{% extends "OspProductBundle::layout.html.twig" %}

{% block OspProduct_body %}
	<h3>Liste des produits</h3>


	<ul class="nav nav-pills nav-stacked">
		<table class="table table-striped">
			<thead>
				<tr>
					<th>ID</th>
					<th>Photo</th>
					<th>Catégorie</th>
					<th>Libellé</th>
					<th>Description</th>
					<th>Lien</th>
					<th>Poids</th>
					<th>Prix</th>
				</tr>
			</thead>
			
			<tbody>
				{% for product in products %}
				<tr>
					<td>{{product.id}}</td>
					<td><img src="{{asset('img/')}}{{ product.photo }}" alt={{product.photo}} height="120" width="120" /></td>
					<td>{{product.categorie.libelle}}</td>
					<td>{{product.libelle}}</td>
					<td>{{ product.description | truncate(20, true, '...') }}</td>
					<td>{{product.lien}}</td>
					<td>{{product.poids ~ ' kg'}}</td>
					<td>{{product.prix ~ ' €'}}</td>
					<td>
						<a href="{{ path('osp_product_update', {'id' : product.id}) }}">
							<img src="{{ asset('img/update.png') }}" alt="Modifier" height="27" width="27" />
						</a>
					</td>
					<td>

						<a href="{{ path('osp_product_delete', {'id' : product.id}) }}" onclick="return confirm('Êtes-vous sûr ? Toutes les commandes possédant ce produit seront supprimées !')">
							<img src="{{ asset('img/delete.png') }}" alt="Supprimer" height="27" width="27" />
						</a>
					</td>
				</tr>	
				{% endfor %}
			</tbody>
		</table>

		{%if error%}
		{{error}}
		{%endif%}

		<br/>
		<br/>

<div class="well form-inline">
	<form method="post" {{ form_enctype(form) }}>
		
		<legend>Créer un produit</legend>
		<table class="table table-striped">
			<thead>
				<tr>
					<th>Photo</th>
					<th>Catégorie</th>
					<th>Libellé</th>
					<th>Description</th>
				</tr>
			</thead>
			
			<tbody>
				<tr>
					<td>{{ form_widget(form.photo, { 'attr': {'class': 'input-small'} }) }}</td>
					<td>{{ form_widget(form.categorie, { 'attr': {'class': 'input-small'} }) }}</td>
					<td>{{ form_widget(form.libelle, { 'attr': {'class': 'input-small'} }) }}</td>
					<td>{{ form_widget(form.description, { 'attr': {'class': 'input-small'} }) }}</td>
				</tr>	
			</tbody>

			<thead>
				<tr>
					<th>Lien</th>
					<th>Poids</th>
					<th>Prix</th>
				</tr>
			</thead>

			<tbody>
				<tr>
					<td>{{ form_widget(form.lien, { 'attr': {'class': 'input-small'} }) }}</td>
					<td>{{ form_widget(form.poids, { 'attr': {'class': 'input-small'} }) }}</td>
					<td>{{ form_widget(form.prix, { 'attr': {'class': 'input-small'} }) }}</td>
				</tr>	
			</tbody>
		</table>
		<input type="submit" class="btn btn-primary" value="Créer Produit" style="margin-left:80%" />
		{{ form_rest(form) }}
	</form>
</div>

{% endblock %}